<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>DojoX Google Analytics Test</title>

		<style type="text/css">
			@import "../../../dojo/resources/dojo.css";
			@import "../../../dijit/tests/css/dijitTests.css";
		</style>

		<!-- required: a default theme file -->
		<link rel="stylesheet" id="themeStyles" href="../../../dijit/themes/tundra/tundra.css" />

		<!-- required: dojo.js -->
		<script src="../../../dojo/dojo.js"
			data-dojo-config="parseOnLoad: true, isDebug: true, async:true, usePlainJson: true,
				sendMethod: 'script', sendInterval: 5000,
				analyticsUrl: 'http://dojotoolkit.org/~dmachi/dojo-1.0/dojox/analytics/logger/dojoxAnalytics.php'">
		</script>

		<!-- do not use: only for testing alternate themes -->
		<script src="../../../dijit/tests/_testCommon.js"></script>

		<script>
			require([
				"dojo/ready",
				"dojox/analytics",
				"dojox/analytics/Urchin",
				"dojo/on",
				"dojo/dom-attr",
				"dojo/dom"
			], function(ready, analytics, Urchin, on, domAttr, dom){
				ready(function(){
					var tracker = null;
					var createTracker = function(){
						if(tracker) return;
						// create and initialize Urchin after onLoad. You need a _real_ UA number
						// available from http://google.com/analytics
						tracker = new Urchin({
							acct:"UA-123456-7",
							GAonLoad: function(){
								this.inherited("GAonLoad", arguments);
								// FIXME: preserve context for domAttr
								domAttr("lazy", "disabled", false);
							}
						});
					};
					var trackRandom = function(){
						// FIXME: there is a small window (10ms to 'however long it took to load')
						// that trackPageView is unavailable. use tracker.GAonLoad function to
						// reliably know when the tracker is available.
						tracker.trackPageView("/some-ajax-taggr");
					};
					on(dom.byId("galoader"), "click", createTracker);
					on(dom.byId("lazy"), "click", trackRandom);
				});
			});
		</script>
	</head>
	<body class="tundra">
		<h1>Simple Lazy loading of Google Analytics Code</h1>
		<button id="galoader">Create Tracker</button>
		<button id="lazy" disabled="disabled">Track something</button>
	</body>
</html>
